package day05;

import java.io.File;
import java.math.BigInteger;
import java.util.Arrays;

public class Test01 {
    public static void main(String[] args) {
        String path = "D:\\SnailsCode\\BackEnd\\JavaLearn2";
        showInfo(path);

        BigInteger num = new BigInteger("5000");
        BigInteger[] arr = new BigInteger[num.intValue() + 1];
        Arrays.fill(arr, null); // 使用null表示未计算过
        BigInteger res = fibonacci(num, arr);
        System.out.println(res);
        System.out.println(res.toString().length());
    }

    private static BigInteger fibonacci(BigInteger num, BigInteger[] arr) {
        int n = num.intValue();
        if (n == 1 || n == 2) {
            return BigInteger.ONE; // 第1和第2个斐波那契数是1
        }
        if (arr[n] != null) { // 如果已经计算过，直接返回
            return arr[n];
        }
        // 递归计算并存储结果
        BigInteger res = fibonacci(num.subtract(BigInteger.ONE), arr)
                .add(fibonacci(num.subtract(BigInteger.valueOf(2)), arr));
        arr[n] = res;
        return res;
    }


    private static void showInfo(String path) {
        File file = new File(path);
        File[] files = file.listFiles();
        for (File myFile : files) {
            if (myFile.isFile()) {
                System.out.println(myFile);
            } else {
                showInfo(myFile.getPath());
            }
        }
    }
}
